package com.iemes.controller.warehouse;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.OutreceiptFormMap;
import com.iemes.entity.TransportTransporinfoFormMap;
import com.iemes.entity.UserFormMap;
import com.iemes.mapper.transport.TransporinfoMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;

@RequestMapping("/outreceipt_back/")
@Controller
public class Outreceipt_BacklController extends BaseController {

	@Inject
	private TransporinfoMapper transporinfoMapper;

	// 查看车辆调度明细表，显示按钮
	@RequestMapping("outreceipt_back")
	public String outreceipt_back(Model model) {
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/warehouse/outreceipt_back_list";
	}

	// 车辆调度明细表分页
	@ResponseBody
	@RequestMapping("outreceipt_back_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception {
		TransportTransporinfoFormMap transporinfoFormMap=getFormMap(TransportTransporinfoFormMap.class);
		transporinfoFormMap.put("formCategory", 2);
		List<Map<String, Object>> transport=transporinfoMapper.getAll(transporinfoFormMap);
		LuogicPaging(pageNow, pageSize, transport);
		return pageView;
	}

	// 查看编辑已回单
	@RequestMapping("outreceipt_back_edit")
	public String editUI(Model model) throws Exception {
		String id = getPara("id");
		if(Common.isNotEmpty("id")){
			//根据Id获得车辆调度明细表
			TransportTransporinfoFormMap tInfo=transporinfoMapper.getById(id);
			model.addAttribute("tInfo",tInfo);
			//获得相同tInfoId的已回单
			OutreceiptFormMap outreceiptFormMap=new OutreceiptFormMap();
			outreceiptFormMap.put("tInfoId", tInfo.get("id"));
			List<OutreceiptFormMap> receipt=baseMapper.findByNames(outreceiptFormMap);
			model.addAttribute("receipt",receipt);
		}
		return Common.BACKGROUND_PATH + "/warehouse/outreceipt_back_edit";
	}

	// 修改已回单
	@ResponseBody
	@RequestMapping(value = "outreceipt_back_editEntity")
	@SystemLog(module = "编辑已回单", methods = "已回单-修改已回单") // 凡需要处理业务逻辑的.都需要记录操作日志
	public String editEntity() throws Exception {
		TransportTransporinfoFormMap transporinfoFormMap=getFormMap(TransportTransporinfoFormMap.class);
		transporinfoMapper.editEntity(transporinfoFormMap);
		return "success";
	}
}